#include "script.hpp"
using namespace VN;
static const NameUnit child={{"日本語",{makeText("子供",default_color)}},
{"繁體中文",{makeText("小孩子",default_color)}}},
mother={{"日本語",{makeText("子供の母",default_color)}},
{"繁體中文",{makeText("小孩母親",default_color)}}},
o={{"日本語",{makeText("橘立花",default_color)}},
{"繁體中文",{makeText("橘立花",default_color)}}};

void chelp(GameScene* g){
    g->Wait(270).name->SetName(help);
}

void cherr(GameScene* g){
    g->Wait(270).name->SetName(herr);
}

void cs(GameScene* g){
    g->Wait(270).name->SetName(s);
}

void co(GameScene* g){
    g->Wait(270).name->SetName(o);
}

void cm(GameScene* g){
    g->Wait(270).name->SetName(m);
}

void cq(GameScene* g){
    g->Wait(270).name->SetName(q);
}

void ca(GameScene* g){
    g->Wait(270).name->SetName(a);
}

void cb(GameScene* g){
    g->Wait(270).name->SetName(b);
}

void cx(GameScene* g){
    g->Wait(270).name->SetName();
}

void ct(GameScene* g){
    g->Wait(270).name->SetName(teach);
}

void ci(GameScene* g){
    g->Wait(270).name->SetName(info);
}

void cch(GameScene* g){
    g->Wait(270).name->SetName(child);
}

void cmo(GameScene* g){
    g->Wait(270).name->SetName(mother);
}

void ck(GameScene* g){
    g->Wait(270).name->SetName(k);
}

void cd(GameScene* g){
    g->Wait(270).name->SetName(d);
}

void ce(GameScene* g){
    g->Wait(270).name->SetName(e);
}

void cf(GameScene* g){
    g->Wait(270).name->SetName(f);
}

void cc(GameScene* g){
    g->Wait(270).name->SetName(c);
}

void ch(GameScene* g){
    g->Wait(270).name->SetName(host);
}

void wait(GameScene* g){
    g->Wait(0);
}

void koavert(GameScene* g,int t){
    ShiftVertical(g->GetCharacter(koa),t);
}

void haruvert(GameScene* g){
    g->NextAction(15,[](GameScene* g,int t)->void{
        ShiftVertical(g->GetCharacter(haru),t);
    }).name->SetName(b);
}

void suzuvert(GameScene* g){
    g->NextAction(15,[](GameScene* g,int t)->void{
        ShiftVertical(g->GetCharacter(suzu),t);
    }).name->SetName(c);
}

void corevert(GameScene* g){
    g->NextAction(15,[](GameScene* g,int t)->void{
        ShiftVertical(g->GetCharacter(core),t);
    }).name->SetName(k);
}

void yuukavert(GameScene* g,int t){
    ShiftVertical(g->GetCharacter(yuuka),t);
}

const char *haru="haru",*suzu="suzu",*yuuka="yuuka",*core="core",*face_smile="face-smile",
*face_talk="face-talk",*face_sorry="face-sorry",*yotuba="yotuba",*yotuba2="yotuba2",
*face_surprise="face-surprise",*face_xd="face-xd",*face_normal="face-normal",
*koa="koa",*face_angry="face-angry",*face_mad2="face-mad2",*face_confuse="face-confuse",
*face_worry="face-worry",*face_shy2="face-shy2",*face_mad4="face-mad4",
*black="black",*face_smile2="face-smile2",*face_xdb="face-xdb",
*face_talkb="face-talkb",*face_mad2b="face-mad2b",*roomn="roomn",
*door_open="se_maoudamashii_se_door05",*room3="room3",*curtain="Curtain01-1",
*bell="Doorbell-Ding_Dong02-1",*room="room",*lesson="lesson",*face_mad3="face-mad3",
*cellphone_beep="Cell_Phone-Hardware02-01(Button-Beep)",*crow="Crow-Real_Ambi01-1",
*can_pull="Beverage_Can-Pull_Tab02-1",*seaside="seaside",*yuuyake="yuuyake",
*face_shy3="face-shy3",*face_mad1="face-mad1",*face_sad="face-sad",*face_wink="face-wink",
*rojiura="rojiura",*flash="flash",*kouen="kouen",*riko="riko",*sio="sio";

const TextMod i76=makeText("4576-9GxD：",default_color,0,0,1);

const NameUnit s={{"日本語",{makeText("スタッフ",default_color)}},
    {"繁體中文",{makeText("工作人員",default_color)}}},
m={{"日本語",{makeText("わたし",default_color)}},
    {"繁體中文",{makeText("我",Color::Black,TTF_STYLE_BOLD)}}},
a={{"日本語",{makeText("愛田 こあ",{0xC3,0x57,0x8B,255},TTF_STYLE_BOLD)}},
    {"繁體中文",{makeText("愛田可亞", {0xC3,0x57,0x8B,255},TTF_STYLE_BOLD)}}},
k={{"日本語",{makeText("葉痕 恋愛",{0xC3,0x57,0x8B,255},TTF_STYLE_BOLD)}},
    {"繁體中文",{makeText("葉痕恋愛", {0xC3,0x57,0x8B,255},TTF_STYLE_BOLD)}}},
b={{"日本語",{makeText("五月雨 晴",{0xA1,0xA7,0xB7,255},TTF_STYLE_BOLD)}},
{"繁體中文",{makeText("五月雨晴", {0xA1,0xA7,0xB7,255},TTF_STYLE_BOLD)}}},
c={{"日本語",{makeText("舞風 すず",{0x96,0xC2,0xB8,255},TTF_STYLE_BOLD)}},
{"繁體中文",{makeText("舞風鈴", {0x96,0xC2,0xB8,255},TTF_STYLE_BOLD)}}},
d={{"日本語",{makeText("鵲邑夏",{0xE3,0x97,0x68,255},TTF_STYLE_BOLD)}},
{"繁體中文",{makeText("鵲邑夏", {0xE3,0x97,0x68,255},TTF_STYLE_BOLD)}}},
e={{"日本語",{makeText("星月心桜",{0xE3,0x97,0x68,255},TTF_STYLE_BOLD)}},
{"繁體中文",{makeText("星月心櫻",{0xE3,0x97,0x68,255},TTF_STYLE_BOLD)}}},
f={{"日本語",{makeText("見川璃子",{0xCC,0x99,0xFF,255},TTF_STYLE_BOLD)}},
{"繁體中文",{makeText("見川璃子",{0xCC,0x99,0xFF,255},TTF_STYLE_BOLD)}}},
q={{"日本語",{makeText("???",default_color,TTF_STYLE_BOLD)}},
{"繁體中文",{makeText("???",default_color,TTF_STYLE_BOLD)}}},
teach={{"日本語",{makeText("トレーナー",default_color,TTF_STYLE_BOLD)}},
{"繁體中文",{makeText("訓練員",default_color,TTF_STYLE_BOLD)}}},empty,
info={{"日本語",{makeText("メッセージ",default_color,TTF_STYLE_BOLD)}},
{"繁體中文",{makeText("訊息",default_color,TTF_STYLE_BOLD)}}},
host={{"日本語",{makeText("司会者",default_color)}},
{"繁體中文",{makeText("主持人",default_color)}}},
herr={{"日本語",{makeText("謌?諢",default_color)}},
{"繁體中文",{makeText("謌?諢",default_color)}}},
help={{"日本語",{makeText("マネージャー",default_color)}},
{"繁體中文",{makeText("經紀人",default_color)}}};

int p=0,n=0;
bool yuukab=false,crash2=false,harub=false,koab=false,coreb=false,Hoshidzuki=false,event=false,rin=false,dc=false;

void SaveCallback(FILE* fp){
    fwrite(&p,4,1,fp);
    fwrite(&n,4,1,fp);
    fwrite(&yuukab,1,1,fp);
    fwrite(&crash2,1,1,fp);
    fwrite(&harub,1,1,fp);
    fwrite(&koab,1,1,fp);
    fwrite(&coreb,1,1,fp);
    fwrite(&Hoshidzuki,1,1,fp);
    fwrite(&second,1,1,fp);
    fwrite(&event,1,1,fp);
    fwrite(&rin,1,1,fp);
    fwrite(&dc,1,1,fp);
}

void LoadCallback(FILE* fp){
    fread(&p,4,1,fp);
    fread(&n,4,1,fp);
    fread(&yuukab,1,1,fp);
    fread(&crash2,1,1,fp);
    fread(&harub,1,1,fp);
    fread(&koab,1,1,fp);
    fread(&coreb,1,1,fp);
    fread(&Hoshidzuki,1,1,fp);
    fread(&second,1,1,fp);
    fread(&event,1,1,fp);
    fread(&rin,1,1,fp);
    fread(&dc,1,1,fp);
}

void EndingRoll(GameScene* g){
    static SDL_Rect r{0,0,1280,7727};
    auto s="endingroll";
    if(string(g->CurrentLanguage())=="日本語"){
        s="endingrolljp";
    }
    g->Fadein(g->AddCharacter(flash,{s},r)).AddAction(200,[](GameScene* g,int t)->void{
        if(t==200)g->AddAction(7227,[](GameScene* g,int t)->void{
            g->GetCharacter(flash)->OffsetPosition(0,-1);
            if(t==7227)g->Fadeout(g->GetCharacter(flash)).AddAction(60,[](GameScene* g,int t)->void{
                if(t==60){
                    g->RemoveCharacter(flash).StopMusic().EndGame();
                }
            });
        });
    }).HideDialog();
}
char* cur_state;
int main(int argc,char* argv[]){
    /*
    MFPack::Pack("assets",{"audio/","back/","cg/","core/","flash/",
    "haru/","koa/","mainback/","riko/","sound/","suzu/","yuuka/"});
    return 0;
    */
   /*自定义资源初始化
   FILE* f=fopen("./__","wb");
   unsigned int v=0;
   fwrite(&v,4,1,f);
   fclose(f);
   return 0;*/
   /*
   FILE* f=fopen("./_","wb");
   fwrite("gui/caution.png",15,1,f);
   fclose(f);
   return 0;*/
    FILE* fp=fopen("./_","rb");
    cur_state=new char[32]();
    fread(cur_state,32,1,fp);
    fclose(fp);
    fp=fopen("./___","rb");
    fread(cur_state+31,1,1,fp);
    fclose(fp);
    const char* main_back="hatobit2";
    switch(cur_state[31]){
        case 1:main_back="hatobit3";break;
        case 2:main_back="hatobitblank";break;
    }
    auto ret=Main("Heart beAt(libVN)","gui/window_icon.png",cur_state,"繁體中文","gui/yugothib.ttf",
    {Color::Orange,Color::Orange,Color::Orange,Color::Orange,Color::Orange,
    Color::TomatoRed,Color::GrassGreen,Color::HuPurple,Color::Orange,
    Color::SkyBlueGray,Color::Orange,Color::CoralRed},
    {80,30,30,30,30,40,40,40,40,40,40,40},{
        {"繁體中文",{
            "開始遊戲","讀取存檔","CG鑒賞","設定","退出","返回","音效","音樂","播放速度",
            "正常","較快","標題音樂","存檔名","確定","跳過","自動播放","讀檔","存檔","主菜單","歷史"
        }},
        {"日本語",{
            "スタート","続きから","CG鑑賞","設定","やめる","戻る","SE","BGM","再生速度",
            "普通","早め","MENU BGM","セーブネーム","確認","SKIP","AUTO","LOAD","SAVE","MENU","RE"
        }}
    },"0940",Color::Black,"mainback",main_back,
    "gui/UI_SETTING2.png","gui/textbox.png","gui/namebox.png","back",
    "black","Still In Love",Color::Pink,{
        ResGroup{"core","core/"},
        ResGroup{"haru","haru/"},
        ResGroup{"koa","koa/"},
        ResGroup{"suzu","suzu/"},
        ResGroup{"yuuka","yuuka/"},
        ResGroup{"flash","flash/"},
        ResGroup{"back","back/"},
        ResGroup{"riko","riko/"}
    },{
        Script()
    },SaveCallback,LoadCallback,{{35,125},{137,319},{163,429},{207,546},{30,656},
    {25,620},{250,100},{250,200},{250,300},{160,400},{390,400},{1000,50},{690,400}}
    ,"gui/UI_SETTING1.png","gui/UI_SETTING4.png","gui/UI_SETTING5.png");
    delete[] cur_state;
    return ret;
}